package org.zxp.guava;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 * @program: effectiveJava
 * @description:
 * @author: X-Pacific zhang
 * @create: 2020-08-11 16:57
 **/
public class TestCache {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Cache<String, String> cache = CacheBuilder.newBuilder()
                .expireAfterWrite(2, TimeUnit.SECONDS)
                .build();
        cache.put("1", "1");
        cache.put("2", "2");
        cache.put("3", "3");
        //Thread.sleep(4000);
        cache.invalidate("3");
        System.out.println(cache.getIfPresent("3"));

    }
}
